<!-- 通报modal -->
<template>
  <a-modal
    :bodyStyle="{ padding: '0', 'max-height': '80vh', 'overflow-y': 'auto' }"
    :title="title"
    :width="1000"
    :maskClosable="false"
    :visible="visible"
    @cancel="visible = false"
    :button_loading="button_loading"
  >
    <a slot="footer">
      <a-button @click="visible = false">{{ cancelText }}</a-button>
      <a-button
        v-if="okText == '保存' && actionType != 'view'"
        type="primary"
        @click="handleSubmit"
        >{{ okText }}</a-button
      >
    </a>
    <a-spin :indicator="indicator" :spinning="spinning" :tip="tip">
      <div class="spin-content">
        <a-form
          :form="form"
          :class="{ disable: actionType == 'view' ? true : false }"
        >
          <a-row :gutter="16">
            <a-col class="gutter-row" :span="24">
              <a-form-item v-bind="formItemLayout1" label="企业名称">
                <a-input
                  placeholder="填写企业名称"
                  v-decorator="[
                    'enterprisenName',
                    { rules: [{ required: true, message: '请填写企业名称!' }] },
                  ]"
                />
              </a-form-item>
            </a-col>
            <a-col class="gutter-row" :span="24">
              <a-form-item v-bind="formItemLayout1" label="统一信用代码">
                <a-input
                  placeholder="填写统一信用代码"
                  v-decorator="[
                    'unifiedCreditCode',
                    
                  ]"
                />
                <!-- {
                  rules: [
                    { required: true, message: '请填写统一信用代码!' },
                  ],
                }, -->
              </a-form-item>
            </a-col>
            <a-col class="gutter-row" :span="24">
              <a-form-item v-bind="formItemLayout1" label="法人">
                <a-input
                  placeholder="填写法人"
                  v-decorator="[
                    'legalPerson',
                    
                  ]"
                />
              </a-form-item>
            </a-col>
            <a-col class="gutter-row" :span="24">
              <a-form-item v-bind="formItemLayout1" label="法人电话">
                <a-input
                  placeholder="填写法人电话"
                  v-decorator="[
                    'legalPersonPhone',
                   
                  ]"
                />
              </a-form-item>
            </a-col>
            <a-col class="gutter-row" :span="24">
              <a-form-item v-bind="formItemLayout1" label="负责人">
                <a-input
                  placeholder="填写负责人"
                  v-decorator="[
                    'enterpriseManager',
                    
                  ]"
                />
              </a-form-item>
            </a-col>
            <a-col class="gutter-row" :span="24">
              <a-form-item v-bind="formItemLayout1" label="负责人电话">
                <a-input
                  placeholder="填写负责人电话"
                  v-decorator="[
                    'enterpriseManagerPhone',
                    
                  ]"
                />
              </a-form-item>
            </a-col>
          </a-row>
        </a-form>
      </div>
    </a-spin>
  </a-modal>
</template>

<script>
import Vue from "vue";
import { ACCESS_TOKEN } from "@/store/mutation-types";
import { getImg } from "@/api/students";
import { mergeArraysIntoObjects } from "@/utils/util";
export default {
  //import引入的组件需要注入到对象中才能使用
  components: {},
  props: {
    actionType: {
      type: String,
      required: false,
      default: "add",
    },
  },
  data() {
    //这里存放数据
    return {
      action: "add",
      currentId: null,
      CodeDisabled: false,
      required: false,
      indicator: <a-icon type="loading" style="font-size: 24px" spin />,
      form: this.$form.createForm(this),
      button_loading: false,
      spinning: false,
      tip: null,
      title: "查看",
      visible: false,
      okText: "保存",
      cancelText: "取消",

      formItemLayout: {
        labelCol: {
          xs: { span: 24 },
          sm: { span: 8 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
      },
      formItemLayout1: {
        labelCol: {
          xs: { span: 24 },
          sm: { span: 4 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 20 },
        },
      },
    };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {},
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
  //方法集合
  methods: {
    view(data) {
      if (data) {
        Object.assign(this, {
          spinning: true,
          visible: true,
          CodeDisabled: false,
          currentId: data.id,
        });
        this.initData(data);
      } else {
        this.visible = true;
        this.form.resetFields();
        this.currentId = null;
      }
      switch (this.actionType) {
        case "add":
          this.okText = "保存";
          this.title = "添加企业";
          break;
        case "edit":
          this.okText = "保存";
          this.title = "编辑企业";
          break;
        case "view":
          this.title = "查看企业信息";
          this.okText = "取消";
          break;
      }
    },

    closeModal() {
      this.form.resetFields();
      this.visible = false;
    },

    initData(data) {
      setTimeout(() => {
        this.spinning = false;
        this.form.setFieldsValue({
          enterprisenName: data.enterpriseName,
          unifiedCreditCode: data.unifiedCreditCode,
          legalPerson: data.legalPerson,
          legalPersonPhone: data.legalPersonPhone,
          enterpriseManager: data.enterpriseManager,
          enterpriseManagerPhone: data.enterpriseManagerPhone,
        });
       
      }, 500);
    },

    handleSubmit() {
      let _this = this;
      _this.form.validateFields((err, values) => {
        if (!err) {
          let params = {
            ...values,
            id: _this.currentId,
          };
          _this.$emit("save", { ...params });
        }
      });
    },
  },
};
</script>
<style lang="less" scoped>
//@import url(); 引入公共css类
.spin-content {
  padding: 20px;
}
.tabs_span {
  display: inline-block;
  padding: 0 5px;
  margin-right: 10px;
  border-radius: 5px;
  border: 1px solid #dddddd;
}

.disable {
  pointer-events: none;
}
</style>
